package beyjava.util;

import java.security.SecureRandom;
import java.security.NoSuchAlgorithmException;

/**
 * @author BEYJAVA
 * random Id generator to all system
 */
public class IdGenerator {

  /**
   * @return randomNum  new unique id
   * @exception NoSuchAlgorithmException if cryptographic algorithm is requested but is not available in the environment 
   */
	public static int generateIntId() {
		int randomNum = 0;
	    try {
	      //Initialize SecureRandom
	      //This is a lengthy operation, to be done only upon
	      //initialization of the application
	      SecureRandom prng = SecureRandom.getInstance("SHA1PRNG");
	      //generate a random number
	      randomNum = Integer.valueOf( prng.nextInt() ); 
	      if(randomNum < 0){
	    	  randomNum = randomNum * (-1);
	      }
	    }
	    catch ( NoSuchAlgorithmException ex ) {
	      System.err.println(ex);
	    }
	    return randomNum;
	}
}